<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class product_ctrl extends CI_Controller {

	
	function __construct(){
		parent::__construct();
		$this->load->model('product');
	}
	
	function Save(){
		if( !empty( $_POST ) ) {
			if ($this->input->post('ajax')){
				$action = $this->input->post('action');
				$productName= trim($this->input->post('product'));
				$quantityPerUnit= $this->input->post('quantity');
				$data = array(
						'productname'=>$productName,
						'quantityperunit'=>$quantityPerUnit
				);
				if ($action=="A"){
					$this->product->SaveAdd($data);
				} else {
					$this->product->SaveEdit($data);
					$data['view_data']=json_encode($this->product->getListProduct());
					$this->load->view('module/product_list',$data);
				}
			 	
			}
		}	
	}
	
	function Delete(){
		if( !empty( $_POST ) ) {
			$productName= trim($this->input->post('product'));
			$data = array(
					'productname'=>$productName
			);
			$this->product->Delete($data);
			$data['view_data']=json_encode($this->product->getListProduct());
		    $this->load->view('module/product_list',$data);
		 
		}
			
	}
	
	function Refresh(){
		$data['view_data']=json_encode($this->product->getListProduct());
		$this->load->view('module/product_list',$data);
	}
}